﻿<views:MvxWpfView 
	x:Class="Sidvall.LogManager.UI.Wpf.Views.LogScopeView"
	xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"  
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
	xmlns:views="clr-namespace:MvvmCross.Wpf.Views;assembly=MvvmCross.Wpf"
	xmlns:vms="clr-namespace:Sidvall.LogManager.UI.ViewModels;assembly=Sidvall.LogManager.UI"
	xmlns:Controls="clr-namespace:Sidvall.LogManager.UI.Wpf.Controls" 
	xmlns:Converters="clr-namespace:Sidvall.UI.Wpf.Converters;assembly=Sidvall.UI.Wpf" 
	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
	xmlns:local="clr-namespace:Sidvall.LogManager.UI.Wpf.Views"
	xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
	mc:Ignorable="d" 
	d:DesignHeight="500" d:DesignWidth="800">

	<views:MvxWpfView.Resources>
		<Converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
		<Converters:BooleanToVisibilityConverter x:Key="NotBooleanToVisibilityConverter" Not="True"/>
	</views:MvxWpfView.Resources>

	<Grid d:DataContext="{d:DesignInstance IsDesignTimeCreatable=True, Type={x:Type vms:LogScopeViewModel}}">
		<Grid.Background>
			<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.InactiveBorderColorKey}}"/>
		</Grid.Background>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="Auto" />
			<RowDefinition/>
			<RowDefinition Height="Auto" />
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="180" />
			<ColumnDefinition />
		</Grid.ColumnDefinitions>

		<Controls:HeaderControl Grid.ColumnSpan="2" HeaderCaption="{Binding Title}" />

		<Grid Grid.Row="1">
			<Grid.Background>
				<SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
			</Grid.Background>
			<StackPanel Orientation="Horizontal">
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.LogManager.UI.Wpf;component/Images/Add.png" 
										ToolTip="Add" ButtonText="{Binding AddTreeItemCaption}" IsEnabled="{Binding CanAddTreeItem}" ButtonCommand="{Binding AddTreeItemCommand}" />
			</StackPanel>
		</Grid>
		<DataGrid Grid.Row="2" ItemsSource="{Binding TreeItems}" AutoGenerateColumns="False" HeadersVisibility="None" CanUserReorderColumns="False" CanUserResizeColumns="False" RowHeaderWidth="0"
			CanUserResizeRows="False" CanUserSortColumns="False" SelectionMode="Single" CanUserAddRows="False" SelectedItem="{Binding ActiveTreeItem, Mode=TwoWay}" AllowDrop="True" Background="#FFF0F0F0">
			<i:Interaction.Triggers>
				<i:EventTrigger EventName="SelectionChanged">
					<i:InvokeCommandAction Command="{Binding SelectTreeItemCommand}" />
				</i:EventTrigger>
			</i:Interaction.Triggers>
			<DataGrid.Columns>
				<DataGridTemplateColumn Width="*">
					<DataGridTemplateColumn.CellTemplate>
						<DataTemplate>
							<Grid>
								<Grid Visibility="{Binding IsServer, Converter={StaticResource BooleanToVisibilityConverter}}" ToolTip="{Binding ItemTooltip}" Background="#FF6AA8C5">
									<Grid.RowDefinitions>
										<RowDefinition Height="40" />
									</Grid.RowDefinitions>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="40" />
										<ColumnDefinition />
									</Grid.ColumnDefinitions>
									<Image Margin="5" Source="/Sidvall.LogManager.UI.Wpf;component/Images/Server.png" Stretch="UniformToFill" />
									<TextBlock Grid.Column="1" Text="{Binding Name}" FontWeight="Bold" Margin="5,0,0,0" VerticalAlignment="Center" FontSize="14" ForceCursor="False" />
								</Grid>
								<Grid Visibility="{Binding IsLogScope, Converter={StaticResource BooleanToVisibilityConverter}}" ToolTip="{Binding ItemTooltip}">
									<Grid.RowDefinitions>
										<RowDefinition Height="30" />
									</Grid.RowDefinitions>
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="30" />
										<ColumnDefinition />
									</Grid.ColumnDefinitions>
									<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="5,0,0,0" VerticalAlignment="Center" Visibility="{Binding IsEnabled, Converter={StaticResource BooleanToVisibilityConverter}}" />
									<TextBlock Grid.Column="1" Text="{Binding Name}" Margin="5,0,0,0" VerticalAlignment="Center" Visibility="{Binding IsEnabled, Converter={StaticResource NotBooleanToVisibilityConverter}}" Opacity="0.2" />
								</Grid>
							</Grid>
						</DataTemplate>
					</DataGridTemplateColumn.CellTemplate>
				</DataGridTemplateColumn>
			</DataGrid.Columns>
		</DataGrid>

		<Grid Grid.Row="1" Grid.Column="1">
			<Grid.Background>
				<SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
			</Grid.Background>
			<StackPanel Orientation="Horizontal">
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.LogManager.UI.Wpf;component/Images/Save.png" 
										ToolTip="Save" ButtonCommand="{Binding SaveActiveTreeItemCommand}" IsEnabled="{Binding CanSave}" />
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.LogManager.UI.Wpf;component/Images/Refresh.png" 
										ToolTip="Reload" ButtonCommand="{Binding SelectTreeItemCommand}" IsEnabled="{Binding CanSave}" />
				<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.LogManager.UI.Wpf;component/Images/Delete.png" 
										ToolTip="Remove" ButtonCommand="{Binding DeleteActiveTreeItemCommand}" IsEnabled="{Binding CanDelete}" />
			</StackPanel>
		</Grid>
		<Grid Grid.Row="2" Grid.Column="1" Grid.RowSpan="2" IsEnabled="{Binding HasActiveLogScope}">
			<Grid.RowDefinitions>
				<RowDefinition Height="Auto" />
				<RowDefinition Height="Auto" />
				<RowDefinition />
				<RowDefinition Height="Auto" />
			</Grid.RowDefinitions>
			<Grid.ColumnDefinitions>
				<ColumnDefinition />
			</Grid.ColumnDefinitions>

			<Grid Grid.Row="1">
				<StackPanel>
					<Grid Margin="5,5,5,0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<Label Content="Id"/>
						<TextBox Grid.Column="1" Text="{Binding ActiveLogScope.LogScopeId, Mode=OneWay}" Width="80" HorizontalAlignment="Left" IsReadOnly="True" />
					</Grid>
					<Grid Margin="5,5,5,0">
						<Grid.ColumnDefinitions>
							<ColumnDefinition Width="130" />
							<ColumnDefinition />
						</Grid.ColumnDefinitions>

						<Label Content="Name"/>
						<TextBox Grid.Column="1" Text="{Binding ActiveLogScope.Name}" />
					</Grid>
				</StackPanel>
			</Grid>
			<TabControl Grid.Row="2" Margin="5,5,5,0">
				<TabItem Header="Log Items">
					<Grid>
						<Grid Visibility="{Binding EventItemListIsVisible, Converter={StaticResource BooleanToVisibilityConverter}}">
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition />
								<RowDefinition Height="Auto" />
							</Grid.RowDefinitions>
							<Grid.ColumnDefinitions>
								<ColumnDefinition />
							</Grid.ColumnDefinitions>

							<Grid>
								<StackPanel>
									<Grid Margin="5,5,5,0">
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="Auto" />
											<ColumnDefinition Width="100" />
											<ColumnDefinition Width="Auto" />
											<ColumnDefinition Width="150" />
											<ColumnDefinition Width="Auto" />
											<ColumnDefinition />
										</Grid.ColumnDefinitions>

										<Label Grid.Column="0" Content="Event type:"/>
										<ComboBox Grid.Column="1" SelectedValuePath="Value" DisplayMemberPath="Key" SelectedValue="{Binding LogContext.EventTypeId}" ItemsSource="{Binding EventTypes}" />
										<Label Grid.Column="2" Content="Category:"/>
										<ComboBox Grid.Column="3" Text="{Binding LogContext.Category}" ItemsSource="{Binding Categories}" IsEditable="True" />
										<Label Grid.Column="4" Content="Content:"/>
										<TextBox Grid.Column="5" Text="{Binding LogContext.Content}" />
									</Grid>
									<Grid Margin="5,5,5,0">
										<Grid.ColumnDefinitions>
											<ColumnDefinition Width="Auto" />
											<ColumnDefinition />
										</Grid.ColumnDefinitions>

										<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.LogManager.UI.Wpf;component/Images/Search.png" 
										ToolTip="Search" ButtonCommand="{Binding SearchCommand}" IsEnabled="{Binding CanSearch}" ButtonText="Search" />
									</Grid>
								</StackPanel>
							</Grid>
							<DataGrid Grid.Row="1" RowHeaderWidth="0" ItemsSource="{Binding LogScopeItems}" AutoGenerateColumns="False" SelectionMode="Single" CanUserAddRows="False" SelectedItem="{Binding ActiveLogScopeItem, Mode=TwoWay}">
								<i:Interaction.Triggers>
									<i:EventTrigger EventName="MouseDoubleClick">
										<i:InvokeCommandAction Command="{Binding EditEventItemCommand}" CommandParameter="{Binding ActiveLogScopeItem}" />
									</i:EventTrigger>
								</i:Interaction.Triggers>
								<DataGrid.Columns>
									<DataGridTextColumn Header="Id" Binding="{Binding LogScopeItemId, Mode=OneWay}" IsReadOnly="True" Width="50" />
									<DataGridTextColumn Header="Event Type" Binding="{Binding EventTypeName, Mode=OneWay}" IsReadOnly="True" Width="120" />
									<DataGridTextColumn Header="Time stamp" Binding="{Binding CreatedTime, Mode=OneWay}" IsReadOnly="True" Width="120" />
									<DataGridTextColumn Header="User" Binding="{Binding IdentityName, Mode=OneWay}" IsReadOnly="True" Width="120" />
									<DataGridTextColumn Header="Title" Binding="{Binding Title, Mode=OneWay}" IsReadOnly="True" Width="*" />
									<DataGridTemplateColumn Width="35" IsReadOnly="True">
										<DataGridTemplateColumn.CellTemplate>
											<DataTemplate>
												<Button Width="32" Height="32" Background="{x:Null}" BorderBrush="{x:Null}" 
															Command="{Binding DataContext.EditEventItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:LogScopeView}}}"
															CommandParameter="{Binding}">
													<Image Source="/Sidvall.LogManager.UI.Wpf;component/Images/Information.png" ToolTip="Information" />
												</Button>
											</DataTemplate>
										</DataGridTemplateColumn.CellTemplate>
									</DataGridTemplateColumn>
								</DataGrid.Columns>
							</DataGrid>
						</Grid>
						<Grid Visibility="{Binding EventItemListIsVisible, Converter={StaticResource NotBooleanToVisibilityConverter}}">
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="Auto" />
								<RowDefinition />
							</Grid.RowDefinitions>

							<Grid>
								<Grid.Background>
									<SolidColorBrush Color="#FFD1E0F1" Opacity="0.6"/>
								</Grid.Background>
								<StackPanel Orientation="Horizontal">
									<Controls:ButtonControl ImageHeight="36" ImageWidth="36" ImageSource="/Sidvall.LogManager.UI.Wpf;component/Images/Back.png" 
											ToolTip="Back to list" ButtonCommand="{Binding ShowEventItemListCommand}" />
								</StackPanel>
							</Grid>

							<StackPanel Grid.Row="1">
								<Grid Margin="5,5,5,0">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="100" />
										<ColumnDefinition />
									</Grid.ColumnDefinitions>

									<Label Content="Auth Type:"/>
									<TextBox Grid.Column="1" Text="{Binding ActiveLogScopeItem.IdentityAuthenticationType, Mode=OneWay}" />
								</Grid>
								<Grid Margin="5,5,5,0">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="100" />
										<ColumnDefinition />
									</Grid.ColumnDefinitions>

									<Label Content="User:"/>
									<TextBox Grid.Column="1" Text="{Binding ActiveLogScopeItem.IdentityName, Mode=OneWay}" />
								</Grid>
								<Grid Margin="5,5,5,0">
									<Grid.ColumnDefinitions>
										<ColumnDefinition Width="100" />
										<ColumnDefinition />
									</Grid.ColumnDefinitions>

									<Label Content="Categories:"/>
									<TextBox Grid.Column="1" Text="{Binding ActiveLogScopeItem.CategoryNames, Mode=OneWay}" />
								</Grid>
							</StackPanel>

							<Grid Grid.Row="2" Margin="5,5,5,0">
								<Grid.RowDefinitions>
									<RowDefinition Height="Auto" />
									<RowDefinition />
								</Grid.RowDefinitions>
								<Label Content="Message" />
								<TextBox Grid.Row="1" Text="{Binding ActiveLogScopeItem.Message}" IsReadOnly="True" VerticalScrollBarVisibility="Visible" AcceptsReturn="True" TextWrapping="Wrap" />
							</Grid>
						</Grid>
					</Grid>
				</TabItem>
			</TabControl>
		</Grid>
	</Grid>
</views:MvxWpfView>
